package io.xiyou.order.listener;

import com.alibaba.fastjson.JSON;
import io.xiyou.goods.api.bo.CreateOrderBO;
import io.xiyou.order.service.support.OrderSupport;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @ClassName：KafkaMessageListener
 * @Author：西柚
 * @Date：2021/11/3 10:46 上午
 * @Versiion：1.0
 */
@Slf4j
@Component
public class KafkaMessageListener {

    @Autowired
    private OrderSupport orderSupport;

    @KafkaListener(topics = "${spring.kafka.topic-name}")
    public void createOrder(String message) {
        log.info("接收消息: {}", message);

        CreateOrderBO createOrderBO = JSON.parseObject(message, CreateOrderBO.class);

        orderSupport.createOrder(createOrderBO);

    }

}
